package com.study.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class SimpleInterceptor implements HandlerInterceptor{
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		System.out.println("SimpleInterceptor的preHandle方法。。。。");
		boolean fag=false;
		String servletPath = request.getServletPath();
		System.out.println(servletPath+"                servletPath");
		String attribute = (String) request.getSession().getAttribute("username");
		System.out.println(attribute);
		if(attribute==null) {
			fag=false;
			//response.sendRedirect("login");
		}else {
			fag=true;
		}
		return fag;
	}
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		System.out.println("SimpleInterceptor的postHandle方法。。2。。");
	}
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		System.out.println("SimpleInterceptor的afterCompletion方法。。3。。");
	}
}
